package com.gzz.mybatis.common.conditices;

import com.gzz.orchid.common.boot.mybatis.conditices.rule.*;
import com.gzz.orchid.common.boot.mybatis.conditices.section.AbstractSection;
import com.gzz.orchid.common.boot.mybatis.conditices.section.ICompare;
import com.gzz.orchid.common.boot.mybatis.conditices.section.INested;

import java.util.function.Consumer;

/**
 * 查询条件
 * @author higmd
 */
public class QueryCondition extends AbstractSection<QueryCondition> implements ICompare<QueryCondition, String>, INested<QueryCondition, QueryCondition> {
    @Override
    protected QueryCondition instance() {
        return new QueryCondition();
    }

    public QueryCondition() {
        super();
    }

    @Override
    public QueryCondition eq(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new NormRegular(column, SqlSymbol.EQ, this.lastSymbol, val));
    }

    @Override
    public QueryCondition ne(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new NormRegular(column, SqlSymbol.NE, this.lastSymbol, val));
    }

    @Override
    public QueryCondition gt(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new NormRegular(column, SqlSymbol.GT, this.lastSymbol, val));
    }

    @Override
    public QueryCondition ge(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new NormRegular(column, SqlSymbol.GE, this.lastSymbol, val));
    }

    @Override
    public QueryCondition lt(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new NormRegular(column, SqlSymbol.LT, this.lastSymbol, val));
    }

    @Override
    public QueryCondition le(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new NormRegular(column, SqlSymbol.LE, this.lastSymbol, val));
    }

    @Override
    public QueryCondition between(boolean flg, String column, Object val1, Object val2) {
        return this.appendRegular(flg, new BetweenRegular(column, SqlSymbol.BETWEEN, this.lastSymbol, val1, val2));
    }

    @Override
    public QueryCondition notBetween(boolean flg, String column, Object val1, Object val2) {
        return this.appendRegular(flg, new BetweenRegular(column, SqlSymbol.NOT_BETWEEN, this.lastSymbol, val1, val2));
    }

    @Override
    public QueryCondition like(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new LikeRegular(column, SqlSymbol.LIKE,this.lastSymbol, val, LikeRegular.SCOPE.BOTH));
    }

    @Override
    public QueryCondition notLike(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new LikeRegular(column, SqlSymbol.NOT_LIKE,this.lastSymbol, val, LikeRegular.SCOPE.BOTH));
    }

    @Override
    public QueryCondition notLikeLeft(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new LikeRegular(column, SqlSymbol.NOT_LIKE,this.lastSymbol, val, LikeRegular.SCOPE.LEFT));
    }

    @Override
    public QueryCondition notLikeRight(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new LikeRegular(column, SqlSymbol.NOT_LIKE,this.lastSymbol, val, LikeRegular.SCOPE.RIGHT));
    }

    @Override
    public QueryCondition likeLeft(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new LikeRegular(column, SqlSymbol.LIKE,this.lastSymbol, val, LikeRegular.SCOPE.LEFT));
    }

    @Override
    public QueryCondition likeRight(boolean flg, String column, Object val) {
        return this.appendRegular(flg, new LikeRegular(column, SqlSymbol.LIKE,this.lastSymbol, val, LikeRegular.SCOPE.RIGHT));
    }

    @Override
    public QueryCondition or(boolean flg) {
        return this.appendRegular(flg, new OrRegular(this.lastSymbol));
    }

    @Override
    public QueryCondition in(boolean flg, String column, Object... val) {
        return this.appendRegular(flg, new InRegular(column, this.lastSymbol, val));
    }

    @Override
    public QueryCondition and(boolean flg, Consumer<QueryCondition> consumer) {
        return this.appendSection(flg, consumer, SqlSymbol.AND);
    }

    @Override
    public QueryCondition or(boolean flg, Consumer<QueryCondition> consumer) {
        return this.appendSection(flg, consumer, SqlSymbol.OR);
    }
}
